package main

import (
	"net/http"
	"fmt"
	"html/template"
	"encoding/json"
	"time"
)



func templateHandler(w http.ResponseWriter, r *http.Request){
	tmpl := `<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Go Web Programming</title>
    </head>
    <body>
        {{ . }}
    </body>
</html>`

	t := template.New("layout.html")
	t, _ = t.Parse(tmpl)
	fmt.Println(t.Name())
	t.Execute(w, "Hello World")

}

const (
	RET_SUCC  int = iota
	INPUT_ERROR
	INPUT_ERROR1
	INPUT_ERROR2
	INPUT_ERROR3
	INPUT_ERROR4
	INPUT_ERROR5
)
var ERRORMSG = map[int]string {
	RET_SUCC:"操作成功",
	INPUT_ERROR:"输入信息有误",
	INPUT_ERROR2:"cuowu",
	INPUT_ERROR3:"sdadasd",
}

type DrugStoreDB struct {
	UserId        string `json:"user_id"`			  // 登录时返回的user id
	CreateTime	  int64 `json:"create_time"`			// 这个条目创建的时间
	Key           string `json:"key"`                 // 药品键值
	Name          string `json:"name"`                // 药品名或条形码
	Specs         string `json:"specs"`     // 规格
	Producer      string `json:"producer"` // 供应商
	PurchasePrice string `json:"purchase_price"`      //进货价
	SalePrice     string `json:"sale_price"`          // 出货价
	BatchNumber   int32  `json:"batch_number"`        // 批号
	Threshold     int32    `json:"threshold"`           // 阈值
	ValidTime     string `json:"valid_time"`          // 有效期
}



func main() {
	db := DrugStoreDB{}
	db.BatchNumber = 123
	db.PurchasePrice = "PurchasePrice"
	db.Name = "name"
	db.CreateTime = time.Now().Unix()
	db.SalePrice = "SalePrice"
	mystr,_ := json.Marshal(db)

	db = DrugStoreDB{}
	json.Unmarshal(mystr, &db)
	fmt.Println(db)
	/*
	fmt.Println(ERRORMSG[INPUT_ERROR3])
	fmt.Println(ERRORMSG[INPUT_ERROR2])
	fmt.Println(ERRORMSG[RET_SUCC])
	http.HandleFunc("/", templateHandler)
	err := http.ListenAndServe(":9090", nil)
	fmt.Println(err)
	*/
}

